﻿namespace WMS6.Web.Outbound
{
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using WMS6.Web;
    using WMS6.Web.BaseInfoServiceRef;
    using WMS6.Web.OutboundService2Ref;

    public class Loading : BasePage
    {
        protected HtmlInputButton btnAction;
        protected Button btnAddDetail;
        protected Button btnAddPickDetail;
        protected Button btnDelete;
        protected Button btnDeleteDetail;
        protected Button btnDeletePickDetail;
        protected Button btnGoBack;
        protected Button btnNew;
        protected Button btnSave;
        protected DropDownList ddlLoadSequence;
        protected DropDownList ddlStatus;
        protected HtmlForm F7056;
        protected GridView gvLoadDetail;
        protected GridView gvLoadPickDetail;
        protected HtmlInputHidden hdnActionID;
        protected HtmlInputHidden hdncalendarFlag;
        protected HtmlInputHidden hdnDataFormat;
        protected HtmlInputHidden hdnFlag;
        protected HtmlInputHidden hdnFrom;
        protected HtmlInputHidden hdnLineID;
        protected HtmlInputHidden hdnLoadID;
        protected HtmlInputHidden hdnLoadPickDetailLineID;
        protected HtmlInputHidden hdnOrderID;
        protected HtmlHead Head1;
        protected HtmlInputButton htmlbtnReport;
        protected HtmlImage img2;
        protected HtmlImage img3;
        protected HtmlImage imgCarrierID;
        protected Label lbl;
        protected Label lblBeginLoadTime;
        protected Label lblCarrierAddress;
        protected Label lblCarrierCity;
        protected Label lblCarrierContact;
        protected Label lblCarrierCountry;
        protected Label lblCarrierFax;
        protected Label lblCarrierID;
        protected Label lblCarrierID2;
        protected Label lblCarrierMail;
        protected Label lblCarrierName;
        protected Label lblCarrierPhone;
        protected Label lblCarrierProv;
        protected Label lblCarrierRef;
        protected Label lblCarrierZIP;
        protected Label lblCreatedBy;
        protected Label lblCreatedDate;
        protected Label lblDepartureTime;
        protected Label lblDoor;
        protected Label lblDriverName;
        protected Label lblEndLoadTime;
        protected Label lblExternalID;
        protected Label lblLoad;
        protected Label lblLoadBy;
        protected Label lblLoadID;
        protected Label lblLoadSequence;
        protected Label lblMsg;
        protected Label lblRemark;
        protected Label lblRoute;
        protected Label lblStatus;
        protected Label lblTotalCount;
        protected Label lblTotalCube;
        protected Label lblTotalUnits;
        protected Label lblTotalWeight;
        protected Label lblUdf04;
        protected Label lblUdf09;
        protected Label lblUdf1;
        protected Label lblUdf10;
        protected Label lblUdf2;
        protected Label lblUdf3;
        protected Label lblUdf5;
        protected Label lblUdf6;
        protected Label lblUdf7;
        protected Label lblUdf8;
        protected Label lblUpdatedBy;
        protected Label lblUpdatedDate;
        protected Label lblVehicleNumber;
        protected Label lblVehicleType;
        protected LinkButton lnkbtnClose;
        protected LinkButton lnkbtnNewLPN;
        protected LinkButton lnkbtnNewOrder;
        protected LinkButton lnkbtnNewPick;
        protected LinkButton lnkbtnPrintLoading;
        protected LinkButton lnkbtnServed;
        protected LinkButton lnkbtnShipping;
        protected HtmlLink mycss;
        protected Label one1;
        protected Label one2;
        protected Label one3;
        protected Label one4;
        protected Label one5;
        protected ScriptManager ScriptManager1;
        protected HtmlTableCell tdlnkbtnClose;
        protected HtmlTableCell tdlnkbtnNewLPN;
        protected HtmlTableCell tdlnkbtnNewOrder;
        protected HtmlTableCell tdlnkbtnNewPick;
        protected HtmlTableCell tdlnkbtnPrintLoading234;
        protected HtmlTableCell tdlnkbtnServed;
        protected HtmlTableCell tdlnkbtnShipping;
        protected TextBox txt;
        protected TextBox txtBeginLoadTime;
        protected TextBox txtCarrierAddress;
        protected TextBox txtCarrierCity;
        protected TextBox txtCarrierContact;
        protected TextBox txtCarrierCountry;
        protected TextBox txtCarrierFax;
        protected TextBox txtCarrierID;
        protected TextBox txtCarrierID2;
        protected TextBox txtCarrierMail;
        protected TextBox txtCarrierName;
        protected TextBox txtCarrierPhone;
        protected TextBox txtCarrierProv;
        protected TextBox txtCarrierRef;
        protected TextBox txtCarrierZIP;
        protected TextBox txtCreatedBy;
        protected TextBox txtCreatedDate;
        protected TextBox txtDepartureTime;
        protected TextBox txtDoor;
        protected TextBox txtDriverName;
        protected TextBox txtEndLoadTime;
        protected TextBox txtExternalID;
        protected TextBox txtLoadBy;
        protected TextBox txtLoadID;
        protected TextBox txtRemark;
        protected TextBox txtRoute;
        protected TextBox txtTotalCount;
        protected TextBox txtTotalCube;
        protected TextBox txtTotalUnits;
        protected TextBox txtTotalWeight;
        protected TextBox txtUdf1;
        protected TextBox txtUdf10;
        protected TextBox txtUdf2;
        protected TextBox txtUdf3;
        protected TextBox txtUdf4;
        protected TextBox txtUdf5;
        protected TextBox txtUdf6;
        protected TextBox txtUdf7;
        protected TextBox txtUdf8;
        protected TextBox txtUdf9;
        protected TextBox txtUpdatedBy;
        protected TextBox txtUpdatedDate;
        protected TextBox txtVehicleNumber;
        protected TextBox txtVehicleType;

        protected void btnAddDetail_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(this.hdnOrderID.Value))
            {
                try
                {
                    this.lblMsg.Text = "新增装车单明细" + OutboundService2ClientProxy.GetInstance().InsertLoadDetailInfo(this.hdnOrderID.Value, this.txtLoadID.Text, this.hdnLineID.Value) + "成功!";
                    this.hdnOrderID.Value = "";
                    this.SetLoadInfo2Form();
                }
                catch (Exception ex)
                {
                    this.lblMsg.Text = ex.Message;
                }
                finally
                {
                    ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',4,5);</script>", false);
                }
            }
        }

        protected void btnAddPickDetail_Click(object sender, EventArgs e)
        {
        }

        protected void btnDelete_Click(object sender, EventArgs e)
        {
            if (this.ddlStatus.SelectedValue.ToUpper() != "NEW")
            {
                this.lblMsg.Text = "状态不等于新建不能删除!";
            }
            else
            {
                try
                {
                    List<string> loadIDs = new List<string> {
                        this.txtLoadID.Text.Trim()
                    };
                    this.lblMsg.Text = "删除装车单号:" + OutboundService2ClientProxy.GetInstance().DeleteLoadInfo(loadIDs) + "成功!";
                    this.btnSave.Enabled = false;
                    this.btnDelete.Enabled = false;
                    this.btnAction.Disabled = true;
                    this.btnAddDetail.Enabled = false;
                    this.btnDeleteDetail.Enabled = false;
                    this.btnAddPickDetail.Enabled = false;
                    this.btnDeletePickDetail.Enabled = false;
                }
                catch (Exception ex)
                {
                    this.lblMsg.Text = ex.Message;
                }
            }
        }

        protected void btnDeleteDetail_Click(object sender, EventArgs e)
        {
            List<string> lineID = base.GetSelectedIDsInGridView(this.gvLoadDetail, "LineID");
            if ((lineID == null) || (lineID.Count == 0))
            {
                this.lblMsg.Text = "请至少选择一项进行删除操作";
            }
            else
            {
                try
                {
                    this.lblMsg.Text = "删除装车单明细:" + OutboundService2ClientProxy.GetInstance().DeleteLoadDetailInfo(this.txtLoadID.Text, lineID) + "成功!";
                    this.SetLoadInfo2Form();
                }
                catch (Exception ex)
                {
                    this.lblMsg.Text = ex.Message;
                }
                finally
                {
                    ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',4,5);</script>", false);
                }
            }
        }

        protected void btnDeletePickDetail_Click(object sender, EventArgs e)
        {
        }

        protected void btnGoBack_Click(object sender, EventArgs e)
        {
            base.Response.Redirect("LoadingList.aspx?from=edit", false);
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.ddlStatus.SelectedValue.ToUpper() == "NEW")
                {
                    if (this.hdnFlag.Value == "1")
                    {
                        this.UpdateLoadInfo();
                    }
                    else
                    {
                        this.InsertLoadInfo();
                    }
                    this.btnAddDetail.Enabled = true;
                    this.btnDeleteDetail.Enabled = true;
                    this.btnAddPickDetail.Enabled = true;
                    this.btnDeletePickDetail.Enabled = true;
                    this.btnDelete.Enabled = true;
                }
                else
                {
                    this.lblMsg.Text = "装车单不为新建状态,不可进行更新操作!";
                }
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = ex.Message;
            }
        }

        private LoadHeaderInfo GetloadInfoInfo()
        {
            return (base.PageQueryEntityViewState as LoadHeaderInfo);
        }

        protected void gvLoadDetail_Init(object sender, EventArgs e)
        {
            base.InitDetailGridView("F7056", this.gvLoadDetail);
        }

        protected void gvLoadDetail_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Cells[0].Text = (e.Row.RowIndex + 1).ToString();
                e.Row.Attributes.Add("onmouseout", "GridViewRowMouseout(this);");
                e.Row.Attributes.Add("onmouseover", "GridViewRowMouseover(this);");
                ((CheckBox) e.Row.FindControl("chbSelect")).Attributes.Add("onclick", "GridViewCheckBoxClick('" + e.Row.ClientID + "')");
                if (this.hdnActionID.Value != "EXPORT")
                {
                    base.SetGridViewLongTextLabel((Label) e.Row.FindControl("lblRemark"));
                }
            }
        }

        protected void gvLoadDetail_Sorting(object sender, GridViewSortEventArgs e)
        {
            try
            {
                string sortDirection = string.Empty;
                if (base.GridViewSortDirection == SortDirection.Ascending)
                {
                    base.GridViewSortDirection = SortDirection.Descending;
                    sortDirection = "DESC";
                }
                else
                {
                    base.GridViewSortDirection = SortDirection.Ascending;
                    sortDirection = "ASC";
                }
                DataView dv = CADataConverter.ToDataTable(this.GetloadInfoInfo().LoadDetailInfos).DefaultView;
                dv.Sort = e.SortExpression + " " + sortDirection;
                base.BindData2GridView(this.gvLoadDetail, dv);
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = ex.Message;
            }
            finally
            {
                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',4,5);</script>", false);
            }
        }

        protected void gvLoadPickDetail_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Cells[0].Text = (e.Row.RowIndex + 1).ToString();
                e.Row.Attributes.Add("onmouseout", "GridViewRowMouseout(this);");
                e.Row.Attributes.Add("onmouseover", "GridViewRowMouseover(this);");
                ((CheckBox) e.Row.FindControl("chbSelect")).Attributes.Add("onclick", "GridViewCheckBoxClick('" + e.Row.ClientID + "')");
            }
        }

        private void InsertLoadInfo()
        {
            try
            {
                LoadHeaderInfo loadInfo = new LoadHeaderInfo();
                loadInfo = this.SetLoadInfoForm(loadInfo);
                loadInfo.CreatedBy = base.UserInfo.UserID;
                string loadID = OutboundService2ClientProxy.GetInstance().InsertLoadInfo(loadInfo);
                loadInfo.LoadID = loadID;
                this.lblMsg.Text = loadID + base.GetGlobalMsgResource("F4100_009");
                this.txtLoadID.Text = loadID;
                this.SetloadInfo(loadInfo);
                this.hdnFlag.Value = "1";
                this.hdnLoadID.Value = loadID;
                this.hdnLineID.Value = "10";
                this.txtLoadID.Enabled = false;
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = ex.Message;
            }
        }

        protected void lnkbtnClose_Click(object sender, EventArgs e)
        {
        }

        protected void lnkbtnNewLPN_Click(object sender, EventArgs e)
        {
        }

        protected void lnkbtnNewOrder_Click(object sender, EventArgs e)
        {
        }

        protected void lnkbtnNewPick_Click(object sender, EventArgs e)
        {
        }

        protected void lnkbtnServed_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.ddlStatus.SelectedValue.ToUpper() == "SHIPPED")
                {
                    this.lblMsg.Text = "装车单" + OutboundService2ClientProxy.GetInstance().UpdateLoadAndOrderStatusByLoadID("Delivery", this.txtLoadID.Text.Trim()) + "状态更新成功!";
                    this.SetLoadInfo2Form();
                }
                else
                {
                    this.lblMsg.Text = "只有发货完成的装车单才能执行签收操作!";
                }
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = ex.Message;
            }
            finally
            {
                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>$.unblockUI();</script>", false);
            }
        }

        protected void lnkbtnShipping_Click(object sender, EventArgs e)
        {
            try
            {
                List<string> OrderID = new List<string>();
                int shippedCounter = 0;
                for (int i = 0; i < this.gvLoadDetail.Rows.Count; i++)
                {
                    if (this.gvLoadDetail.DataKeys[i]["Status"].ToString().ToUpper() != "SHIPPED")
                    {
                        OrderID.Add(this.gvLoadDetail.DataKeys[i]["OrderID"].ToString());
                        shippedCounter++;
                    }
                }
                string result = OutboundServiceClientProxy.GetInstance().ShippedByOrderID(OrderID, DateTime.Now.ToString());
                if (this.gvLoadDetail.Rows.Count == shippedCounter)
                {
                    OutboundService2ClientProxy.GetInstance().UpdateLoadAndOrderStatusByLoadID("Shipped", this.txtLoadID.Text.Trim());
                }
                this.SetLoadInfo2Form();
                if (!string.IsNullOrEmpty(result))
                {
                    base.ShowMsgLabel(this.lblMsg, string.Format(base.GetGlobalMsgResource("F7600_008"), result));
                }
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = ex.Message;
            }
            finally
            {
                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>$.unblockUI();</script>", false);
            }
        }

        private void LoadData()
        {
            base.BindData2DDLBySysCode(this.ddlStatus, "LoadStatus");
            base.BindData2DDLBySysCode(this.ddlLoadSequence, "LoadingOrder");
            if (!string.IsNullOrEmpty(base.Request.QueryString["ID"]))
            {
                this.hdnLoadID.Value = base.Request.QueryString["ID"];
                this.hdnFlag.Value = "1";
                this.txtLoadID.Enabled = false;
                this.SetLoadInfo2Form();
            }
            else
            {
                this.txtDepartureTime.Text = base.GetPreferenceShortDate(DateTime.Now);
                this.txtBeginLoadTime.Text = base.GetPreferenceShortDate(DateTime.Now);
                this.txtEndLoadTime.Text = base.GetPreferenceShortDate(DateTime.Now);
                this.btnAddDetail.Enabled = false;
                this.btnDeleteDetail.Enabled = false;
                this.btnDelete.Enabled = false;
                this.btnAddPickDetail.Enabled = false;
                this.btnDeletePickDetail.Enabled = false;
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!base.IsPostBack)
            {
                base.InitPage(this.Page);
                this.LoadData();
            }
            this.lblMsg.Text = "";
        }

        private void SetloadInfo(LoadHeaderInfo loadHeaderInfo)
        {
            base.PageQueryEntityViewState = loadHeaderInfo;
        }

        private void SetLoadInfo2Form()
        {
            string LoadID = this.hdnLoadID.Value;
            LoadHeaderInfo loadHeaderInfo = OutboundService2ClientProxy.GetInstance().GetLoadByID(LoadID);
            if (loadHeaderInfo != null)
            {
                this.txtLoadID.Text = loadHeaderInfo.LoadID;
                this.ddlStatus.SelectedValue = loadHeaderInfo.Status;
                this.txtExternalID.Text = loadHeaderInfo.ExternalID;
                this.txtDepartureTime.Text = base.GetPreferenceShortDate(loadHeaderInfo.DepartureTime);
                this.txtCarrierID.Text = loadHeaderInfo.CarrierID;
                this.txtVehicleType.Text = loadHeaderInfo.VehicleType;
                this.txtVehicleNumber.Text = loadHeaderInfo.VehicleNumber;
                this.txtBeginLoadTime.Text = base.GetPreferenceShortDate(loadHeaderInfo.BeginLoadTime);
                this.txtEndLoadTime.Text = base.GetPreferenceShortDate(loadHeaderInfo.EndLoadTime);
                this.txtDriverName.Text = loadHeaderInfo.DriverName;
                this.txtLoadBy.Text = loadHeaderInfo.LoadBy;
                this.txtRoute.Text = loadHeaderInfo.Route;
                this.txtDoor.Text = loadHeaderInfo.Door;
                this.ddlLoadSequence.SelectedValue = loadHeaderInfo.LoadSequence;
                this.txtTotalCube.Text = base.GetPreferenceDigit(loadHeaderInfo.TotalCube);
                this.txtTotalWeight.Text = base.GetPreferenceDigit(loadHeaderInfo.TotalWeight);
                this.txtTotalUnits.Text = base.GetPreferenceDigit(loadHeaderInfo.TotalUnits);
                this.txtCarrierID2.Text = loadHeaderInfo.CarrierID;
                this.txtCarrierAddress.Text = loadHeaderInfo.CarrierAddress;
                this.txtCarrierCity.Text = loadHeaderInfo.CarrierCity;
                this.txtCarrierContact.Text = loadHeaderInfo.CarrierContact;
                this.txtCarrierCountry.Text = loadHeaderInfo.CarrierCountry;
                this.txtCarrierFax.Text = loadHeaderInfo.CarrierFax;
                this.txtCarrierMail.Text = loadHeaderInfo.CarrierEmail;
                this.txtCarrierName.Text = loadHeaderInfo.CarrierName;
                this.txtCarrierPhone.Text = loadHeaderInfo.CarrierPhone;
                this.txtCarrierProv.Text = loadHeaderInfo.CarrierProv;
                this.txtCarrierRef.Text = loadHeaderInfo.CarrierRef;
                this.txtCarrierZIP.Text = loadHeaderInfo.CarrierZip;
                this.txtUdf1.Text = loadHeaderInfo.Udf1;
                this.txtUdf2.Text = loadHeaderInfo.Udf2;
                this.txtUdf3.Text = loadHeaderInfo.Udf3;
                this.txtUdf4.Text = loadHeaderInfo.Udf4;
                this.txtUdf5.Text = loadHeaderInfo.Udf5;
                this.txtUdf6.Text = loadHeaderInfo.Udf6;
                this.txtUdf7.Text = loadHeaderInfo.Udf7;
                this.txtUdf8.Text = loadHeaderInfo.Udf8;
                this.txtUdf9.Text = loadHeaderInfo.Udf9;
                this.txtUdf10.Text = loadHeaderInfo.Udf10;
                this.txtRemark.Text = "";
                this.txtCreatedBy.Text = loadHeaderInfo.CreatedBy;
                this.txtCreatedDate.Text = base.GetPreferenceShortDate(loadHeaderInfo.CreatedDate);
                this.txtUpdatedBy.Text = loadHeaderInfo.UpdatedBy;
                this.txtUpdatedDate.Text = base.GetPreferenceShortDate(loadHeaderInfo.UpdatedDate);
                if (loadHeaderInfo.Status != "New")
                {
                    this.btnAddDetail.Enabled = false;
                    this.btnDeleteDetail.Enabled = false;
                }
                if (loadHeaderInfo.LoadDetailInfos != null)
                {
                    base.BindData2GridView(this.gvLoadDetail, loadHeaderInfo.LoadDetailInfos);
                    if (loadHeaderInfo.LoadDetailInfos.Count > 0)
                    {
                        int CS00001 = loadHeaderInfo.LoadDetailInfos[loadHeaderInfo.LoadDetailInfos.Count - 1].LineID + 10;
                        this.hdnLineID.Value = CS00001.ToString();
                    }
                    else
                    {
                        this.hdnLineID.Value = "10";
                    }
                    this.txtTotalCount.Text = loadHeaderInfo.LoadDetailInfos.Count.ToString();
                }
                else
                {
                    loadHeaderInfo.LoadDetailInfos = new List<LoadDetailInfo>();
                    this.hdnLineID.Value = "10";
                    this.txtTotalCount.Text = "";
                }
                if (loadHeaderInfo.LoadPickDetailInfos != null)
                {
                    base.BindData2GridView(this.gvLoadPickDetail, loadHeaderInfo.LoadPickDetailInfos);
                    if (loadHeaderInfo.LoadPickDetailInfos.Count > 0)
                    {
                        this.btnAddDetail.Enabled = false;
                        this.btnDeleteDetail.Enabled = false;
                        this.hdnLoadPickDetailLineID.Value = (loadHeaderInfo.LoadPickDetailInfos[loadHeaderInfo.LoadPickDetailInfos.Count - 1].LineID + 10).ToString();
                    }
                    else
                    {
                        this.hdnLoadPickDetailLineID.Value = "10";
                    }
                }
                else
                {
                    loadHeaderInfo.LoadPickDetailInfos = new List<LoadPickDetailInfo>();
                    this.hdnLoadPickDetailLineID.Value = "10";
                }
                this.SetloadInfo(loadHeaderInfo);
            }
        }

        private LoadHeaderInfo SetLoadInfoForm(LoadHeaderInfo loadInfo)
        {
            DateTime dt = DateTime.Now;
            decimal outDec = 0.0M;
            LoadHeaderInfo loadHeaderInfo = loadInfo;
            loadHeaderInfo.LoadID = this.txtLoadID.Text.Trim();
            loadHeaderInfo.ExternalID = this.txtExternalID.Text.Trim();
            loadHeaderInfo.Status = this.ddlStatus.SelectedValue;
            if (DateTime.TryParse(this.txtDepartureTime.Text.Trim(), out dt))
            {
                loadHeaderInfo.DepartureTime = DateTime.Parse(this.txtDepartureTime.Text.Trim());
            }
            else
            {
                loadHeaderInfo.DepartureTime = DateTime.Now;
            }
            loadHeaderInfo.CarrierID = this.txtCarrierID.Text.Trim();
            loadHeaderInfo.VehicleType = this.txtVehicleType.Text;
            loadHeaderInfo.VehicleNumber = this.txtVehicleNumber.Text.Trim();
            if (DateTime.TryParse(this.txtBeginLoadTime.Text.Trim(), out dt))
            {
                loadHeaderInfo.BeginLoadTime = DateTime.Parse(this.txtBeginLoadTime.Text.Trim());
            }
            else
            {
                loadHeaderInfo.BeginLoadTime = DateTime.Now;
            }
            if (DateTime.TryParse(this.txtEndLoadTime.Text.Trim(), out dt))
            {
                loadHeaderInfo.EndLoadTime = DateTime.Parse(this.txtEndLoadTime.Text.Trim());
            }
            else
            {
                loadHeaderInfo.EndLoadTime = DateTime.Now;
            }
            loadHeaderInfo.DriverName = this.txtDriverName.Text.Trim();
            loadHeaderInfo.LoadBy = this.txtLoadBy.Text.Trim();
            loadHeaderInfo.Route = this.txtRoute.Text.Trim();
            loadHeaderInfo.Door = this.txtDoor.Text.Trim();
            loadHeaderInfo.LoadSequence = this.ddlLoadSequence.SelectedValue;
            if (!string.IsNullOrEmpty(this.txtTotalCube.Text.Trim()))
            {
                loadHeaderInfo.TotalCube = double.Parse(this.txtTotalCube.Text.Trim());
            }
            else
            {
                loadHeaderInfo.TotalCube = 0.0;
            }
            if (decimal.TryParse(this.txtTotalUnits.Text.Trim(), out outDec))
            {
                loadHeaderInfo.TotalUnits = decimal.Parse(this.txtTotalUnits.Text.Trim());
            }
            else
            {
                loadHeaderInfo.TotalUnits = outDec;
            }
            if (!string.IsNullOrEmpty(this.txtTotalWeight.Text.Trim()))
            {
                loadHeaderInfo.TotalWeight = double.Parse(this.txtTotalWeight.Text.Trim());
            }
            else
            {
                loadHeaderInfo.TotalWeight = 0.0;
            }
            loadHeaderInfo.CarrierName = this.txtCarrierName.Text;
            loadHeaderInfo.CarrierPhone = this.txtCarrierPhone.Text;
            loadHeaderInfo.CarrierProv = this.txtCarrierProv.Text;
            loadHeaderInfo.CarrierRef = this.txtCarrierRef.Text;
            loadHeaderInfo.CarrierZip = this.txtCarrierZIP.Text;
            loadHeaderInfo.CarrierEmail = this.txtCarrierMail.Text;
            loadHeaderInfo.CarrierFax = this.txtCarrierFax.Text;
            loadHeaderInfo.CarrierCountry = this.txtCarrierCountry.Text;
            loadHeaderInfo.CarrierContact = this.txtCarrierContact.Text;
            loadHeaderInfo.CarrierCity = this.txtCarrierCity.Text;
            loadHeaderInfo.CarrierAddress = this.txtCarrierAddress.Text;
            loadHeaderInfo.Udf1 = this.txtUdf1.Text.Trim();
            loadHeaderInfo.Udf2 = this.txtUdf2.Text.Trim();
            loadHeaderInfo.Udf3 = this.txtUdf3.Text.Trim();
            loadHeaderInfo.Udf4 = this.txtUdf4.Text.Trim();
            loadHeaderInfo.Udf5 = this.txtUdf5.Text.Trim();
            loadHeaderInfo.Udf6 = this.txtUdf6.Text.Trim();
            loadHeaderInfo.Udf7 = this.txtUdf7.Text.Trim();
            loadHeaderInfo.Udf8 = this.txtUdf8.Text.Trim();
            loadHeaderInfo.Udf9 = this.txtUdf9.Text.Trim();
            loadHeaderInfo.Udf10 = this.txtUdf10.Text.Trim();
            return loadHeaderInfo;
        }

        protected void txtCarrierID_TextChanged(object sender, EventArgs e)
        {
            CarrierInfo tradePartnerInfo = BaseInfoServiceClientProxy.GetInstance().GetInfoByID(this.txtCarrierID.Text.Trim(), "CARRIER") as CarrierInfo;
            if (!((tradePartnerInfo == null) || string.IsNullOrEmpty(tradePartnerInfo.CarrierID)))
            {
                this.txtCarrierName.Text = tradePartnerInfo.Company;
                this.txtCarrierAddress.Text = tradePartnerInfo.Address;
                this.txtCarrierCity.Text = tradePartnerInfo.City;
                this.txtCarrierContact.Text = tradePartnerInfo.Contact1;
                this.txtCarrierCountry.Text = tradePartnerInfo.Country;
                this.txtCarrierMail.Text = tradePartnerInfo.Email1;
                this.txtCarrierFax.Text = tradePartnerInfo.Fax1;
                this.txtCarrierPhone.Text = tradePartnerInfo.Phone1;
                this.txtCarrierProv.Text = tradePartnerInfo.State;
                this.txtCarrierZIP.Text = tradePartnerInfo.Zip;
                this.txtCarrierID2.Text = tradePartnerInfo.CarrierID;
                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',2,5);</script>", false);
            }
            this.txtCarrierID.Focus();
        }

        private void UpdateLoadInfo()
        {
            try
            {
                if (this.ddlStatus.SelectedValue.ToUpper() != "NEW")
                {
                    this.lblMsg.Text = base.GetGlobalMsgResource("F4100_006");
                }
                else
                {
                    LoadHeaderInfo loadInfo = this.GetloadInfoInfo();
                    loadInfo = this.SetLoadInfoForm(loadInfo);
                    loadInfo.UpdatedBy = base.UserInfo.UserID;
                    this.lblMsg.Text = "更新" + OutboundService2ClientProxy.GetInstance().UpdateLoadInfo(loadInfo) + "成功!";
                }
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = base.GetGlobalMsgResource("F4100_008") + ex.Message;
            }
        }
    }
}

